#!/bin/bash 

basedir=`dirname $0`
options=""
while [ $# -gt 1 ]; do
    options="$options $1"
    shift
done
config="$1"
if [ ! -e "$config" ]; then
    echo "Syntax error: requires a .ini file to work with." >&2
    exit 1
fi

dot=`echo "$config" | sed 's/\.ini$/.dot/g'`
png=`echo "$config" | sed 's/\.ini$/.png/g'`

python2 $basedir/workflow_parser.py $options "$config" "$dot"
if [ $? -ne 0 ]; then
    echo "Failed to parse \"$config\", exiting." >&2
    exit 1
fi

#cat "$dot"
if [ "$OSTYPE" = cygwin ]; then
    dot -T png -o "$png" "$dot"
    cmd /c start $png
else
    dot -T png -o "$png" "$dot"
display "$png"&
rm "$dot"&
sleep 3
#rm "$png"&
rm "$config"&
fi
